package com.example.bgmachine.bgmachine.popupviews;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.example.bgmachine.bgmachine.R;
import com.example.bgmachine.bgmachine.homes.HomePages;

public class TeaMachineWaitViews extends Dialog implements
        View.OnClickListener {

    private Context context;
    private Boolean bool;
    private View.OnClickListener btnOnClick = null;
    private Button discharge_wait_views_cancel_button = null;

    private ProgressBar material_pup_view_popup_item_progressbar= null;


    public void setBtnOnClick(View.OnClickListener btnOnClick) {
        this.btnOnClick = btnOnClick;
        // material_validity_periodViews_keys_button.setOnClickListener(btnOnClick);

    }

    public TeaMachineWaitViews(Context context) {
        super(context, R.style.SundayTransDialogs);
        this.context = context;
        bool = true;


        Log.d("aaa", "aaa===2");
        //create();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.discharge_wait_views_dialog);
        hideBottomUIMenu();
        // 设置窗口属性
        if (getWindow() != null) {
            getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            getWindow().setDimAmount(0f);
            getWindow().setFlags(
                    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
                    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
            );
            getWindow().setFlags(
                    WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                    WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
            );
        }
        init();


    }

    /**
     * 隐藏虚拟按键，并且全屏
     */
    protected void hideBottomUIMenu() {
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.MATCH_PARENT;
        getWindow().setAttributes(params);


        int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN;
        Window myWindow = this.getWindow();
        myWindow.setFlags(flag, flag);

        //隐藏虚拟按键，并且全屏
        if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
            View v = this.getWindow().getDecorView();
            v.setSystemUiVisibility(View.GONE);
        } else if (Build.VERSION.SDK_INT >= 19) {
            //for new api versions.
            View decorView = getWindow().getDecorView();
            int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(uiOptions);


        }

        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN);
        getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN);
            }
        });
    }


    private void init() {

        discharge_wait_views_cancel_button = findViewById(R.id.discharge_wait_views_cancel_button);
        discharge_wait_views_cancel_button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {


                dismiss();
                HomePages.mHomePages.cancelTeaMachine();


            }
        });



        material_pup_view_popup_item_progressbar = findViewById(R.id.material_pup_view_popup_item_progressbar);

    }

    @Override
    public void show() {
        super.show();


    }

    @Override
    public void dismiss() {
        super.dismiss();

    }

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        if (isShowing()) {
            //   dismiss();
        }
    }

}
